define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function ($, undefined, Backend, Table, Form, undefined) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coupon/couponsetting/index',
                    add_url: 'coupon/couponsetting/add',
                    edit_url: 'coupon/couponsetting/edit',
                    del_url: 'coupon/couponsetting/del',
                    multi_url: 'coupon/couponsetting/multi',
                    table: 'coupon_setting',
                },
                showExport:false
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                commonSearch: true,
                visible: true,
                showToggle: false,
                showColumns: false,
                search:false,
                searchFormVisible:true,
                showExport: false,
                columns: [
                    [
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'name', title: __('name')},
                        {field: 'title', title: __('title')},
                        // {field: 'image', title: __('image'), formatter: Table.api.formatter.image, events: Table.api.events.image},
                        {field: 'money', title: __('money'),operate:false},
                        {field: 'rule', title: '类型', formatter: Table.api.formatter.normal, searchList: {0: "普通",1:"新注用户", 2: "生日券"}},
                        {field: 'get_limit', title: '领取限制',operate:false},
                        {field: 'coupon_nums', title: __('coupon_nums'),operate:false},
                        {field: 'get_nums', title: '已领取数量',operate:false},
                        {field: 'create_time', title: __('create_time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'update_time', title: __('update_time'), formatter: Table.api.formatter.datetime,operate:false, addclass: 'datetimerange', sortable: true},
                        {field: 'status', title: __('status'), formatter: Table.api.formatter.status, searchList: {1: '开启', 2: '关闭'}},
                        {field: 'operate', title: __('operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                $(document).on('click', "input[name='row[date_type]']", function (e, ee) {
                    var dateType = $(this).val();
                    if (dateType == 1) {
                        $(".date_type_1").show();
                        $(".date_type_2").hide();
                    } else {
                        $(".date_type_2").show();
                        $(".date_type_1").hide();
                    }
                });
                $("input[name='row[date_type]']:checked").trigger("click");
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});